﻿#include "PlatformProperty.h"

#define BLOWING_MODE_FACE 1
#define BLOWING_MODE_LEG 2
#define BLOWING_MODE_FACE_AND_LEG 3
#define BLOWING_MODE_FRONT_WINDOW 4
#define BLOWING_MODE_FACE_AND_FRONT_WINDOW 5
#define BLOWING_MODE_LEG_AND_FRONT_WINDOW 6
#define BLOWING_ALL 7
#define BLOWING_AUTO 8

MAPPING_VALUE(sdb::AvailabilitySts, PropertyStatus, PropertyStatus::NotAvailable)
    MAPPING_ITEM(sdb::AvailabilitySts::Active, PropertyStatus::Active)
    MAPPING_ITEM(sdb::AvailabilitySts::NotActive, PropertyStatus::NotActive)
    MAPPING_ITEM(sdb::AvailabilitySts::Error, PropertyStatus::Error)
    MAPPING_ITEM(sdb::AvailabilitySts::NotAvailable, PropertyStatus::NotAvailable)
MAPPING_END

MAPPING_VALUE(int32_t, sdb::HmiCmptmtAirDistbnFrnt, sdb::HmiCmptmtAirDistbnFrnt::Aut)
    MAPPING_ITEM(BLOWING_MODE_FACE, sdb::HmiCmptmtAirDistbnFrnt::Vent)
    MAPPING_ITEM(BLOWING_MODE_LEG, sdb::HmiCmptmtAirDistbnFrnt::Flr)
    MAPPING_ITEM(BLOWING_MODE_FACE_AND_LEG, sdb::HmiCmptmtAirDistbnFrnt::FlrVent)
    MAPPING_ITEM(BLOWING_MODE_FRONT_WINDOW, sdb::HmiCmptmtAirDistbnFrnt::Defrst)
    MAPPING_ITEM(BLOWING_MODE_FACE_AND_FRONT_WINDOW, sdb::HmiCmptmtAirDistbnFrnt::VentDefrst)
    MAPPING_ITEM(BLOWING_MODE_LEG_AND_FRONT_WINDOW, sdb::HmiCmptmtAirDistbnFrnt::FlrDefrst)
    MAPPING_ITEM(BLOWING_ALL, sdb::HmiCmptmtAirDistbnFrnt::FlrVentDefrst)
    MAPPING_ITEM(BLOWING_AUTO, sdb::HmiCmptmtAirDistbnFrnt::Aut)
MAPPING_END

MAPPING_VALUE(sdb::HmiCmptmtAirDistbnFrnt, int32_t, BLOWING_AUTO)
    MAPPING_ITEM(sdb::HmiCmptmtAirDistbnFrnt::Vent, BLOWING_MODE_FACE)
    MAPPING_ITEM(sdb::HmiCmptmtAirDistbnFrnt::Flr, BLOWING_MODE_LEG)
    MAPPING_ITEM(sdb::HmiCmptmtAirDistbnFrnt::FlrVent, BLOWING_MODE_FACE_AND_LEG)
    MAPPING_ITEM(sdb::HmiCmptmtAirDistbnFrnt::Defrst, BLOWING_MODE_FRONT_WINDOW)
    MAPPING_ITEM(sdb::HmiCmptmtAirDistbnFrnt::VentDefrst, BLOWING_MODE_FACE_AND_FRONT_WINDOW)
    MAPPING_ITEM(sdb::HmiCmptmtAirDistbnFrnt::FlrDefrst, BLOWING_MODE_LEG_AND_FRONT_WINDOW)
    MAPPING_ITEM(sdb::HmiCmptmtAirDistbnFrnt::FlrVentDefrst, BLOWING_ALL)
    MAPPING_ITEM(sdb::HmiCmptmtAirDistbnFrnt::Aut, BLOWING_AUTO)
MAPPING_END

SYSTEM_READ_WRITE_PROPERTY(HVAC_FAN_DIRECTION, int32_t) {
    builder
        .configArray(std::vector<int32_t>{BLOWING_MODE_FACE, BLOWING_MODE_LEG,
                                          BLOWING_MODE_FACE_AND_LEG, BLOWING_MODE_FRONT_WINDOW,
                                          BLOWING_MODE_FACE_AND_FRONT_WINDOW,
                                          BLOWING_MODE_LEG_AND_FRONT_WINDOW, BLOWING_ALL, BLOWING_AUTO})
        .area(VehicleAreaSeat::ROW_1_LEFT | VehicleAreaSeat::ROW_1_RIGHT)
        .initValue([]() { return static_cast<int32_t>(sdb::HmiCmptmtAirDistbnFrnt::Aut); })
        .withStatusBySignals(
            []([[maybe_unused]] const PropertyStatus& lastStatus) {
                sdb::AvailabilitySts availabilitySts =
                    sdb::AvailabilitySts(SIGNAL.getPA_CL_ModeFrstLeft().availability);
                PropertyStatus status = mappingValue(availabilitySts, PropertyStatus::NotAvailable);
                VHALOG.d(
                    "HVAC_FAN_DIRECTION row_1_left status changed to: availabilitySts = %d, status "
                    "= %d",
                    availabilitySts, status);
                return status;
            },
            PASignal::PA_CL_ModeFrstLeft)
        .withValueBySignals(
            []([[maybe_unused]] const int32_t& last) {
                sdb::HmiCmptmtAirDistbnFrnt data =
                    (sdb::HmiCmptmtAirDistbnFrnt)SIGNAL.getPA_CL_ModeFrstLeft().data;
                int32_t apidata = mappingValue(data, BLOWING_AUTO);
                VHALOG.d("HVAC_FAN_DIRECTION row_1_left value changed to: data = %d, apidata = %d",
                      data, apidata);
                return apidata;
            },
            PASignal::PA_CL_ModeFrstLeft)
        .onSetProperty([](const int32_t& value) {
            sdb::HmiCmptmtAirDistbnFrnt mode =
                mappingValue(value, sdb::HmiCmptmtAirDistbnFrnt::Aut);
            VHALOG.d("halOnSetProperty HVAC_FAN_DIRECTION row_1_left value : %d mode is : %d ", value,
                  mode);
            SIGNAL.setCB_CL_ModeFrstLeft(mode);
        })
        .configArray(
            std::vector<int32_t>{BLOWING_MODE_FACE, BLOWING_MODE_LEG, BLOWING_MODE_FACE_AND_LEG, BLOWING_AUTO})
        .area(VehicleAreaSeat::ROW_2_LEFT | VehicleAreaSeat::ROW_2_RIGHT)
        .initValue([]() { return static_cast<int32_t>(sdb::HmiCmptmtAirDistbnFrnt::Aut); })
        .withStatusBySignals(
            []([[maybe_unused]] const PropertyStatus& lastStatus) {
                sdb::AvailabilitySts availabilitySts =
                    sdb::AvailabilitySts(SIGNAL.getPA_CL_ModeSec().availability);
                PropertyStatus status = mappingValue(availabilitySts, PropertyStatus::NotAvailable);
                VHALOG.d(
                    "HVAC_FAN_DIRECTION row_2_left status changed to: availabilitySts = %d, status "
                    "= %d",
                    availabilitySts, status);
                return status;
            },
            PASignal::PA_CL_ModeSec)
        .withValueBySignals(
            []([[maybe_unused]] const int32_t& last) {
                sdb::HmiCmptmtAirDistbnFrnt data =
                    (sdb::HmiCmptmtAirDistbnFrnt)SIGNAL.getPA_CL_ModeSec().data;
                int32_t apidata = mappingValue(data, BLOWING_AUTO);
                VHALOG.d("HVAC_FAN_DIRECTION row_2_left value changed to: data = %d, apidata = %d",
                      data, apidata);
                return apidata;
            },
            PASignal::PA_CL_ModeSec)
        .onSetProperty([](const int32_t& value) {
            VHALOG.d("halOnSetProperty HVAC_FAN_DIRECTION row_2_left: %d", value);

            sdb::HmiCmptmtAirDistbnFrnt mode =
                mappingValue(value, sdb::HmiCmptmtAirDistbnFrnt::Aut);
            SIGNAL.setCB_CL_ModeSec(mode);
        });
}